package name.bingo.bing.concurrent.red.packet.front;

import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import name.bingo.bing.concurrent.red.packet.model.TUserRedPacket;
import name.bingo.bing.concurrent.red.packet.service.TUserRedPacketReadService;
import name.bingo.bing.concurrent.red.packet.service.TUserRedPacketWriteService;
import name.bingo.common.model.Paging;
import name.bingo.common.utils.RespHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author [ your email ]
 * @date 2019-03-22 13:40:22
 * Created by CodeGen .
 */
@Api(tags = {""})
@Slf4j
@RestController
@RequestMapping
public class TUserRedPackets {

    @Autowired
    private TUserRedPacketWriteService tUserRedPacketWriteService;

    @Autowired
    private TUserRedPacketReadService tUserRedPacketReadService;

    @ApiOperation("鏌ヨ")
    @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public TUserRedPacket findTUserRedPacket(@PathVariable Long id) {
        return RespHelper.or500(tUserRedPacketReadService.findById(id));
    }

    @ApiOperation("鍒嗛〉")
    @GetMapping(value = "/paging", produces = MediaType.APPLICATION_JSON_VALUE)
    public Paging<TUserRedPacket> pagingTUserRedPacket(@RequestParam(value = "pageNo", required = false) Integer pageNo,
                                                       @RequestParam(value = "pageSize", required = false) Integer pageSize) {

        Map<String, Object> criteria = Maps.newHashMap();
        return RespHelper.or500(tUserRedPacketReadService.paging(pageNo, pageSize, criteria));
    }

    @ApiOperation("鍒涘缓")
    @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    public Long createTUserRedPacket(@RequestBody TUserRedPacket tUserRedPacket) {
        return RespHelper.or500(tUserRedPacketWriteService.create(tUserRedPacket));
    }

    @ApiOperation("鏇存柊")
    @PutMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    public Boolean updateTUserRedPacket(@RequestBody TUserRedPacket tUserRedPacket) {
        return RespHelper.or500(tUserRedPacketWriteService.update(tUserRedPacket));
    }

    @ApiOperation("鍒犻櫎")
    @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public Boolean deleteTUserRedPacket(@PathVariable Long id) {
        return false;
    }

    @ApiOperation("鍒楄〃")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<TUserRedPacket> listTUserRedPacket() {
        Map<String, Object> criteria = Maps.newHashMap();
        return RespHelper.or500(tUserRedPacketReadService.list(criteria));
    }
}
